package cn.broadsense.thrid.api;

import cn.broadsense.thrid.constant.DaHuaApiUrlConstant;
import cn.broadsense.thrid.param.BaseParam;
import cn.broadsense.thrid.param.ChannelStatusParam;
import cn.broadsense.thrid.param.NewChannelParam;
import cn.broadsense.thrid.result.BasePageResult;
import cn.broadsense.thrid.result.ChannelOrgResult;
import cn.broadsense.thrid.result.ChannelStatusResult;
import cn.broadsense.thrid.result.NewChannelResult;
import cn.broadsense.thrid.utils.DaHuaHttpUtils;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 点位相关
 *
 * @author: pengxin
 * @create: 2023-09-18 14:48
 * @Version 1.0
 **/
@Component
public class ChannelRepository extends BaseRepository {

    /**
     * 获取组织列表
     *
     * @return
     */
    public List<JSONObject> channelOrgList(int page, int pageSize, int layer, Long orgType) {
        String dhToken = getCToken();
        BaseParam param = new BaseParam() {
            @Override
            public void checkParam() {

            }

            @Override
            public Class getResultClass() {
                return BasePageResult.class;
            }
        };
        param.setUrl(cUrl + String.format(DaHuaApiUrlConstant.VideoApplication.DEVICE_LAYER_ORG, page, pageSize, layer, orgType));

        BasePageResult result = DaHuaHttpUtils.getRest(dhToken, param);
        return result.getResults();
    }


    /**
     * 获取点位列表
     *
     * @param param
     * @return
     */
    public NewChannelResult channelList(NewChannelParam param) {
        String dhToken = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.VideoApplication.ORG_DEVICES_INFO);
        return DaHuaHttpUtils.postRest(dhToken, param);
    }

    /**
     * 获取点位状态
     *
     * @param param
     * @return
     */
    public ChannelStatusResult channelStatus(ChannelStatusParam param) {
        String dhToken = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.VideoApplication.ORG_DEVICES_STATUS);
        return DaHuaHttpUtils.postRest(dhToken, param);
    }


}
